package com.zhl.method;

public class MethodTes4 {
    public static void main(String[] args) {
        //目的：掌握方法设计的技巧
        System.out.println("1到5的和为："+add_1_n_sum(5));
        System.out.println("6是否是奇数："+judge(6));
        System.out.println("7是否是奇数："+judge(7));
        judge1(6);
        judge1(7);
    }

    public static int add_1_n_sum(int n)
    {
        return (n * (n + 1)) / 2;
    }

    public static boolean judge(int n)   {
        boolean flag;
        if (n % 2 ==0){
            flag = false;
        }else{
            flag = true;
        }
        return flag;
    }

    //或者可以这样写
    public static void judge1(int n){
        if (n % 2 ==0){
            System.out.println(n+"是偶数");
        }else{
            System.out.println(n+"是奇数");
        }
    }
}
